// actions集合
import * as actionTypes from './constants';

const deleteItemAction = ((data: number) => {
    return{
        type: actionTypes.DELETE_ITEM,
        data
    }
});
/**
 * 页面: 单个删除
 * @method deleteItem
 * @param index 下标
 * @return dispatch箭头函数 用于提交reducer
 * */
export const deleteItem = (index: number) => {
    return (dispatch: any) => {
        dispatch(deleteItemAction(index))
    }
};

const deleteBatchAction = ((data:number[]) => {
    return{
        type: actionTypes.DELETE_BATCH,
        data
    }
});
/**
 * 页面: 批量删除
 * @method deleteBatch
 * @param indexArr 下标数组
 * @return dispatch箭头函数 用于提交reducer
 * */
export const deleteBatch = (indexArr: number[]) => {
    return (dispatch: any) => {
        dispatch(deleteBatchAction(indexArr))
    }
};

const addItemAction = ((data: any) => {
    return{
        type: actionTypes.ADD_ITEM,
        data
    }
});
/**
 * 页面: 单个增加
 * @method addItem
 * @param 增加对象
 * @return dispatch箭头函数 用于提交reducer
 * */
export const addItem= (obj: any) => {
    return (dispatch: any) => {
        dispatch(addItemAction(obj))
    }
};

const editItemAction = ((index: number,data: any) => {
    return{
        type: actionTypes.EDIT_ITEM,
        index,
        data
    }
});
/**
 * 页面: 修改
 * @method editItem
 * @param index 下标
 * @param data 新对象
 * @return dispatch箭头函数 用于提交reducer
 * */
export const editItem= (index: number,data: any) => {
    return (dispatch: any) => {
        dispatch(editItemAction(index,data))
    }
};